### Does a UBI affect voter turnout ##
##  Replication file for Table A6    ##

#setwd(" ")

library(haven)
library(did)

# Load data. Remember to set up WD before running 
replication_ubiturnout_R <- read_dta("data_ubiturnout_aggregate.dta") 

#Model 1 1978-1982
out <- att_gt(yname = "turnout",
              gname = "firsttreat",
              id = "id",
              t = "year",
              xformla = ~1,
              data = subset(replication_ubiturnout_R, year<1984),
              est_method = "reg"
)
summary(out)
group_effects <- aggte(out, type = "group")
summary(group_effects)

#Model 2 1978-1990
outmt <- att_gt(yname = "turnout",
              gname = "firsttreat",
              id = "id",
              t = "year",
              xformla = ~1,
              data = subset(replication_ubiturnout_R, year<1992),
              est_method = "reg"
)
summary(outmt)
group_effectsms <- aggte(outmt, type = "group")
summary(group_effectsms)

#Model 3 1978-2000
outlt <- att_gt(yname = "turnout",
              gname = "firsttreat",
              id = "id",
              t = "year",
              xformla = ~1,
              data = replication_ubiturnout_R,
              est_method = "reg"
)
summary(outlt)
group_effectslt <- aggte(outlt, type = "group")
summary(group_effectslt)